<template>
  <div class="students-container">
    <div class="page-header">
      <h3>学生管理</h3>
      <el-input
        v-model="searchQuery"
        placeholder="搜索学生"
        style="width: 200px"
        @input="handleSearch">
        <i slot="prefix" class="el-icon-search"></i>
      </el-input>
    </div>

    <el-table :data="filteredStudents" style="width: 100%" v-loading="loading">
      <el-table-column prop="username" label="学号"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="class" label="班级"></el-table-column>
      <el-table-column prop="email" label="邮箱"></el-table-column>
      <el-table-column prop="phone" label="手机号"></el-table-column>
      <el-table-column label="作业完成情况" width="120">
        <template slot-scope="scope">
          {{ scope.row.completedAssignments }}/{{ scope.row.totalAssignments }}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'TeacherStudents',
  data() {
    return {
      loading: false,
      students: [],
      searchQuery: ''
    }
  },
  computed: {
    filteredStudents() {
      if (!this.searchQuery) {
        return this.students
      }
      const query = this.searchQuery.toLowerCase()
      return this.students.filter(item => 
        item.username.toLowerCase().includes(query) ||
        item.name.toLowerCase().includes(query) ||
        item.class.toLowerCase().includes(query)
      )
    }
  },
  created() {
    this.getStudents()
  },
  methods: {
    getStudents() {
      this.loading = true
      // TODO: 调用获取学生列表接口
      setTimeout(() => {
        this.students = [
          {
            id: 1,
            username: '2024001',
            name: '李同学',
            class: '计算机2024级1班',
            email: 'student1@example.com',
            phone: '13800138002',
            completedAssignments: 8,
            totalAssignments: 10
          }
        ]
        this.loading = false
      }, 1000)
    },
    handleSearch() {
      // 实时搜索，不需要额外处理，computed属性会自动过滤
    }
  }
}
</script>

<style scoped>
.students-container {
  background-color: #fff;
  padding: 20px;
  border-radius: 4px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.page-header h3 {
  margin: 0;
}
</style> 